<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.keywords" placeholder="关键字/id/会员id/会员手机号" style="width: 200px;" class="filter-item"
        @keyup.enter.native="handleFilter" />

      <el-select v-model="listQuery.mold_id" placeholder="变动类型" clearable style="width: 150px" class="filter-item">
        <el-option v-for="(item, index) in moldList" :key="index" :label="item.name" :value="item.id" />
      </el-select>
      <datePicker class="filter-item" v-model="listQuery.date"></datePicker>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="getList">搜索</el-button>
    </div>
    <el-table :key="tableKey" v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="ID" prop="id" sortable="custom" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员id" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.member_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员名称" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员手机号" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.phone }}</span>
        </template>
      </el-table-column>
      <el-table-column label="变动金额" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.money > 0" style="color: green;">{{ scope.row.money }}</span>
          <span v-else style="color: red;">{{ scope.row.money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="变动后余额" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.balance }}</span>
        </template>
      </el-table-column>
      <el-table-column label="变动类型" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.mold_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注信息" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.remark }}</span>
        </template>
      </el-table-column>
      <el-table-column label="变动时间" align="center">
        <template slot-scope="{ row }">
          {{ _date(row.create_time) }}
        </template>
      </el-table-column>

    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

  </div>
</template>

<script>
  import {
    financingProfit,
    financingMold
  } from '@/api/members';

  import waves from '@/directive/waves';
  import {
    parseTime
  } from '@/utils';
  import Pagination from '@/components/Pagination';
  import permission from '@/directive/permission/index.js';
  import {
    dateHandle
  } from '@/api/dateHandle';
  import datePicker from '@/components/Upload/datePicker';
  export default {
    components: {
      Pagination,
      datePicker
    },
    directives: {
      waves,
      permission,

    },
    data() {
      return {
        tableKey: 0,
        list: null,
        total: 0,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 10,
          mold_id: null,
          date: []
        },
        moldList: {}
      };
    },
    created() {
      this.getList()
      this.getMold()
    },
    methods: {
      _date(t) {
        return dateHandle('Y-m-d H:i:s', t);
      },
      getMold() {
        financingMold().then(res => {
          this.moldList = res.data
        })
      },
      getList() {
        this.listLoading = true;
        financingProfit(this.listQuery).then(res => {
          this.list = res.data.data;
          this.total = res.data.total;
          setTimeout(() => {
            this.listLoading = false;
          }, 0.3 * 1000);
        });
      },

    }
  };
</script>
